package com.duowei.diandan.bean.food;

import com.duowei.diandan.db.entry.Dmpzsd;
import com.duowei.diandan.db.entry.Jyxmsz;

import java.util.List;
import java.util.Objects;

/**
 * 单品
 */
public class Single implements FoodImpl {
    /** 单品项 */
    private Jyxmsz item;

    /** 买赠列表(单选) */
    private List<Jyxmsz> presentList;

    /** 加价列表(单选) */
    private List<Jyxmsz> addPriceList;

    /** 口味列表(可选) */
    private List<Dmpzsd> tasteList;

    /* 是否是折扣 */
    private boolean hourDiscount;
    /** 有折扣价格时,保存价格 */
    private Float hourDiscountPrice;

    // 标志,处理买赠、加价、口味 时间戳
    private long currentTimePresent;
    private long currentTimeAddPrice;

    public Single(Jyxmsz item) {
        this.item = item;
    }

    public Jyxmsz getItem() {
        return item;
    }

    public void setItem(Jyxmsz item) {
        this.item = item;
    }

    public List<Jyxmsz> getPresentList() {
        return presentList;
    }

    public void setPresentList(List<Jyxmsz> presentList) {
        this.presentList = presentList;
    }

    public List<Jyxmsz> getAddPriceList() {
        return addPriceList;
    }

    public void setAddPriceList(List<Jyxmsz> addPriceList) {
        this.addPriceList = addPriceList;
    }

    public long getCurrentTimePresent() {
        return currentTimePresent;
    }

    public void setCurrentTimePresent(long currentTimePresent) {
        this.currentTimePresent = currentTimePresent;
    }

    public long getCurrentTimeAddPrice() {
        return currentTimeAddPrice;
    }

    public void setCurrentTimeAddPrice(long currentTimeAddPrice) {
        this.currentTimeAddPrice = currentTimeAddPrice;
    }

    public List<Dmpzsd> getTasteList() {
        return tasteList;
    }

    public void setTasteList(List<Dmpzsd> tasteList) {
        this.tasteList = tasteList;
    }

    public boolean isHourDiscount() {
        return hourDiscount;
    }

    public void setHourDiscount(boolean hourDiscount) {
        this.hourDiscount = hourDiscount;
    }


    @Override
    public boolean equals(Object obj) {
        if (obj instanceof Single) {
            Single s = (Single) obj;

            return Objects.equals(this.item, s.item);
        } else {
            return false;
        }
    }

    @Override
    public String getImgNo() {
        if (this.item != null) {
            return this.item.getTm();
        } else {
            return null;
        }
    }

    @Override
    public String getName() {
        if (this.item != null) {
            return this.item.getXmmc();
        } else {
            return null;
        }
    }

    @Override
    public Float getPrice() {
        if (hourDiscount && hourDiscountPrice != null) {
            return hourDiscountPrice;
        } else {
            return this.item.getPrice();
        }
    }

    public Float getHourDiscountPrice() {
        return hourDiscountPrice;
    }

    public void setHourDiscountPrice(Float hourDiscountPrice) {
        this.hourDiscountPrice = hourDiscountPrice;
    }

    @Override
    public Float getMemberPrice() {
        return this.item.getMemberPrice();
    }

    @Override
    public Float getXl() {
        if (this.item != null) {
            return this.item.getXl();
        } else {
            return null;
        }
    }

    /**
     * 是否含有买赠、加价促销项、必选口味
     *
     * @return true, 有; false,无
     */
    public boolean hasPresentOrAddPrice() {
        if ((presentList != null && presentList.size() > 0)
                || (addPriceList != null && addPriceList.size() > 0)
                || (tasteList != null && tasteList.size() > 0)) {
            return true;
        } else {
            return false;
        }
    }
}
